﻿/**
 * AbeBooks UK Search Box
 * Copyright 2007-2008 Doug Bromley <doug.bromley+yourmp@gmail.com>
 * http://www.straw-dogs.co.uk
 * Released under the GNU Public License v3
 * Inspired by Amazon Search Box by Teodor Filimon
 */

options.putDefaultValue("lastWidth",160);
options.putDefaultValue("lastHeight",61);
view.height = options("lastHeight");
view.width = options("lastWidth");
_onSize();

function _onSize(){
	centerBack.width = view.width - 36;
	rightBack.x = view.width - 23;
	editSearch.width = view.width - 40;
	imgGo.x = view.width - 35;
	options("lastWidth") = view.width;
	options("lastHeight") = view.height;
}

/**
 * Executed when a key is pressed.
 * If keypress is [Enter] then executes the goto results function
 */
function _keyPress(){
	if(event.keyCode==13){ 
		gotoSearchResults();
	}
}

function gotoSearchResults(){
	framework.openUrl("http://www.dpbolvw.net/click-3226294-5435709?url=http%3A%2F%2Fwww.abebooks.co.uk%2Fservlet%2FSearchResults%3Ftn%3D" + urlEncode(editSearch.value) + "%26bi%3D0%26bx%3Doff%26ds%3D30%26sortby%3D3%26x%3D40%26y%3D10&cm_mmc=CJ-_-1074909-_-885608-_-Abebooks-Book%20Redirection%20Allowed");
}

/**
 * A tiny hacky urlEncoder. It only encodes spaces!
 */
function urlEncode(s){
	return s.replace(/ /g, "%2B");
}

/**
 * Handling clicking of Go button
 */
function imgGo_onclick() {
	debug.trace('Going');
	gotoSearchResults();
}

